package com.jksoft.darewayyyy.global;

import android.app.Application;
import android.graphics.Bitmap;
import android.os.Environment;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.nostra13.universalimageloader.utils.StorageUtils;

import java.io.File;

/**
 * Created by Administrator on 2015/8/31.
 */
public class MyApplication extends Application {
//    public static String UUID = "FDA50693-A4E2-4FB1-AFCF-C6EB07647825";
//    public static String MAJOR = "10011";
//    public static String MINOR = "62587";
    public static String UUID = "FDA50693-A4E2-4FB1-AFCF-C6EB07647825";
    public static String MAJOR = "10012";
    public static String MINOR = "9297";
    public static boolean debug = true;
    public final static String appPath = Environment.getExternalStorageDirectory().getPath() + "/androidYYY";


    public final static String qrcodeUrl = "http://123.233.247.119/dwCard/servlet/GetQrCodeKey";
    public final static String checkByQrcodeUrl = "http://123.233.247.119/dwCard/servlet/CheckByQrCodeServlet";
    public final static String getUserInfoUrl = "http://123.233.247.119/dwCard/servlet/GetEmployeeInfo";

//    public final static String qrcodeUrl = "http://10.1.98.61:8080/dwCard/servlet/GetQrCodeKey";
//    public final static String checkByQrcodeUrl = "http://10.1.98.61:8080/dwCard/servlet/CheckByQrCodeServlet";
//    public final static String getUserInfoUrl = "http://10.1.98.61:8080/dwCard/servlet/GetEmployeeInfo";
    @Override
    public void onCreate() {
        super.onCreate();

        init();
    }

    private void init() {
        File cacheDir = StorageUtils.getOwnCacheDirectory(
                getApplicationContext(), "imageloader/Cache");
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                this)
                .memoryCacheExtraOptions(480, 800)
                        // max
                .discCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG, 75, null)
                        // Can
                .threadPoolSize(3)
                        // 线程池内加载的数量
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
                        // You
                .memoryCacheSize(2 * 1024 * 1024)
                .discCacheSize(50 * 1024 * 1024)
                .discCacheFileNameGenerator(new Md5FileNameGenerator())
                        // 将保存的时候的URI名称用MD5
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .discCacheFileCount(100)
                        // 缓存的文件数量
                .discCache(new UnlimitedDiscCache(cacheDir))
                        // 自定义缓存路径
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
                .imageDownloader(
                        new BaseImageDownloader(this, 5 * 1000, 30 * 1000)) // connectTimeout
                .build();// 开始构建
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.init(config);
    }
}
